home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_11 / phillip2 / boole.c < prev    next >
C/C++ Source or Header  |  1993-05-22  |  11KB  |  368 lines

  1.  
  2.  
  3.     /***********************************************
  4.     *
  5.     *       file d:\cips\boole.c
  6.     *
  7.     *       Functions: This file contains
  8.     *          and_image
  9.     *          or_image
  10.     *          xor_image
  11.     *          nand_image
  12.     *          nor_image
  13.     *          not_image
  14.     *
  15.     *       Purpose:
  16.     *          These functions implement the basic
  17.     *          Boolean algebra functions AND, OR,
  18.     *          XOR, NAND, NOR, and NOT.
  19.     *
  20.     *       External Calls:
  21.     *          wtiff.c - create_file_if_needed
  22.     *                    write_array_into_tiff_image
  23.     *          tiff.c - read_tiff_header
  24.     *          rtiff.c - read_tiff_image
  25.     *          numcvrt.c - get_integer
  26.     *
  27.     *       Modifications:
  28.     *          3 March 1993 - created
  29.     *
  30.     ***********************************************/
  31.  
  32.  
  33. #include "cips.h"
  34.  
  35.  
  36.  
  37.    /**************************************************
  38.    *
  39.    *   and_image(...
  40.    *
  41.    *   This function performs the Boolean AND 
  42.    *   operation.  The output image = in1 AND in2.
  43.    *   This works for 0 non-zero images.  If both
  44.    *   in1 and in2 are non-zero, the output = in1.
  45.    *
  46.    ***************************************************/
  47.  
  48. and_image(in1_name, in2_name, out_name,
  49.           the_image, out_image,
  50.           il1, ie1, ll1, le1,
  51.           il2, ie2, ll2, le2,
  52.           il3, ie3, ll3, le3)
  53.    char   in1_name[], in2_name[], out_name[];
  54.    int    il1, ie1, ll1, le1,
  55.           il2, ie2, ll2, le2,
  56.           il3, ie3, ll3, le3;
  57.    short  the_image[ROWS][COLS],
  58.           out_image[ROWS][COLS];
  59. {
  60.    int    i, j, length, width;
  61.    struct tiff_header_struct image_header;
  62.  
  63.    create_file_if_needed(in1_name, out_name, out_image);
  64.  
  65.    read_tiff_image(in1_name, the_image,
  66.                    il1, ie1, ll1, le1);
  67.    read_tiff_image(in2_name, out_image,
  68.                    il2, ie2, ll2, le2);
  69.  
  70.    for(i=0; i<ROWS; i++){
  71.       if ( (i%10) == 0) printf(" %d", i);
  72.       for(j=0; j<COLS; j++){
  73.          if( the_image[i][j] != 0   &&
  74.              out_image[i][j] != 0)
  75.              out_image[i][j] = the_image[i][j];
  76.          else
  77.              out_image[i][j] = 0;
  78.       }  /* ends loop over j */
  79.    }  /* ends loop over i */
  80.  
  81.    write_array_into_tiff_image(out_name, out_image,
  82.                                il3, ie3, ll3, le3);
  83.  
  84. } /* ends and_image */
  85.  
  86.  
  87.  
  88.  
  89.  
  90.    /**************************************************
  91.    *
  92.    *   or_image(...
  93.    *
  94.    *   This function performs the Boolean OR 
  95.    *   operation.  The output image = in1 OR in2.
  96.    *   This works for 0 non-zero images.  If both
  97.    *   in1 and in2 are non-zero, the output = in1.
  98.    *   If in1 is non-zero, the output = in1.
  99.    *   If in1 is zero and in2 is non-zero, the
  100.    *   output = in2.
  101.    *
  102.    ***************************************************/
  103.  
  104. or_image(in1_name, in2_name, out_name,
  105.          the_image, out_image,
  106.          il1, ie1, ll1, le1,
  107.          il2, ie2, ll2, le2,
  108.          il3, ie3, ll3, le3)
  109.    char  in1_name[], in2_name[], out_name[];
  110.    int   il1, ie1, ll1, le1,
  111.          il2, ie2, ll2, le2,
  112.          il3, ie3, ll3, le3;
  113.    short the_image[ROWS][COLS],
  114.          out_image[ROWS][COLS];
  115. {
  116.    int    i, j, length, width;
  117.    struct tiff_header_struct image_header;
  118.  
  119.    create_file_if_needed(in1_name, out_name, out_image);
  120.  
  121.    read_tiff_image(in1_name, the_image,
  122.                    il1, ie1, ll1, le1);
  123.    read_tiff_image(in2_name, out_image,
  124.                    il2, ie2, ll2, le2);
  125.  
  126.    for(i=0; i<ROWS; i++){
  127.       if ( (i%10) == 0) printf(" %d", i);
  128.       for(j=0; j<COLS; j++){
  129.          if( the_image[i][j] != 0   ||
  130.              out_image[i][j] != 0){
  131.              if(the_image[i][j] != 0)
  132.                 out_image[i][j] = the_image[i][j];
  133.              else
  134.                 out_image[i][j] = out_image[i][j];
  135.          }
  136.          else
  137.              out_image[i][j] = 0;
  138.       }  /* ends loop over j */
  139.    }  /* ends loop over i */
  140.  
  141.    write_array_into_tiff_image(out_name, out_image,
  142.                                il3, ie3, ll3, le3);
  143.  
  144. } /* ends or_image */
  145.  
  146.  
  147.  
  148.  
  149.  
  150.    /**************************************************
  151.    *
  152.    *   xor_image(...
  153.    *
  154.    *   This function performs the Boolean XOR 
  155.    *   operation.  The output image = in1 XOR in2.
  156.    *   This works for 0 non-zero images.  If 
  157.    *   in1 is non-zero and in2 is 0, output = in1. If
  158.    *   in2 is non-zero and in1 is 0, output = in2.
  159.    *   If both in1 and in2 are non-zero, output = 0.
  160.    *   If both in1 and in2 are zero, output = 0.
  161.    *
  162.    ***************************************************/
  163.  
  164. xor_image(in1_name, in2_name, out_name,
  165.           the_image, out_image,
  166.           il1, ie1, ll1, le1,
  167.           il2, ie2, ll2, le2,
  168.           il3, ie3, ll3, le3)
  169.    char   in1_name[], in2_name[], out_name[];
  170.    int    il1, ie1, ll1, le1,
  171.           il2, ie2, ll2, le2,
  172.           il3, ie3, ll3, le3;
  173.    short  the_image[ROWS][COLS],
  174.           out_image[ROWS][COLS];
  175. {
  176.    int    i, j, length, width;
  177.    short  answer;
  178.    struct tiff_header_struct image_header;
  179.  
  180.    create_file_if_needed(in1_name, out_name, out_image);
  181.  
  182.    read_tiff_image(in1_name, the_image,
  183.                    il1, ie1, ll1, le1);
  184.    read_tiff_image(in2_name, out_image,
  185.                    il2, ie2, ll2, le2);
  186.  
  187.    for(i=0; i<ROWS; i++){
  188.       if ( (i%10) == 0) printf(" %d", i);
  189.       for(j=0; j<COLS; j++){
  190.          if( (the_image[i][j] != 0 &&
  191.               out_image[i][j] == 0))
  192.              answer = the_image[i][j];
  193.          if( (the_image[i][j] == 0 &&
  194.               out_image[i][j] != 0))
  195.              answer = out_image[i][j];
  196.          if( (the_image[i][j] == 0 &&
  197.               out_image[i][j] == 0))
  198.              answer = 0;
  199.          if( (the_image[i][j] != 0 &&
  200.               out_image[i][j] != 0))
  201.              answer = 0;
  202.          out_image[i][j] = answer;
  203.       }  /* ends loop over j */
  204.    }  /* ends loop over i */
  205.  
  206.    write_array_into_tiff_image(out_name, out_image,
  207.                                il3, ie3, ll3, le3);
  208.  
  209. } /* ends xor_image */
  210.  
  211.  
  212.  
  213.  
  214.  
  215.    /**************************************************
  216.    *
  217.    *   nand_image(...
  218.    *
  219.    *   This function performs the Boolean NAND 
  220.    *   operation.  The output image = in1 NAND in2.
  221.    *   This works for 0 non-zero images.  If both
  222.    *   in1 and in2 are non-zero, the output = 0.
  223.    *   Otherwise, the output = value.
  224.    *
  225.    ***************************************************/
  226.  
  227. nand_image(in1_name, in2_name, out_name,
  228.            the_image, out_image,
  229.            il1, ie1, ll1, le1,
  230.            il2, ie2, ll2, le2,
  231.            il3, ie3, ll3, le3, value)
  232.    char    in1_name[], in2_name[], out_name[];
  233.    int     il1, ie1, ll1, le1,
  234.            il2, ie2, ll2, le2,
  235.            il3, ie3, ll3, le3;
  236.    short   the_image[ROWS][COLS],
  237.            out_image[ROWS][COLS], value;
  238. {
  239.    int    i, j, length, width;
  240.    struct tiff_header_struct image_header;
  241.  
  242.    create_file_if_needed(in1_name, out_name, out_image);
  243.  
  244.    read_tiff_image(in1_name, the_image,
  245.                    il1, ie1, ll1, le1);
  246.    read_tiff_image(in2_name, out_image,
  247.                    il2, ie2, ll2, le2);
  248.  
  249.    for(i=0; i<ROWS; i++){
  250.       if ( (i%10) == 0) printf(" %d", i);
  251.       for(j=0; j<COLS; j++){
  252.          if( the_image[i][j] != 0   &&
  253.              out_image[i][j] != 0)
  254.              out_image[i][j] = 0;
  255.          else
  256.              out_image[i][j] = value;
  257.       }  /* ends loop over j */
  258.    }  /* ends loop over i */
  259.  
  260.    write_array_into_tiff_image(out_name, out_image,
  261.                                il3, ie3, ll3, le3);
  262.  
  263. } /* ends nand_image */
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.    /**************************************************
  271.    *
  272.    *   nor_image(...
  273.    *
  274.    *   This function performs the Boolean NOR 
  275.    *   operation.  The output image = in1 NOR in2.
  276.    *   This works for 0 non-zero images.  If niether
  277.    *   in1 nor in2 are non-zero, the output = value.
  278.    *   That is, if both in1 and in2 are zero, the
  279.    *   output = value.
  280.    *
  281.    ***************************************************/
  282.  
  283. no